package org.xs.object.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import org.xs.object.common.JWT_lanJie;
import org.xs.object.dao.user.UserRepository;

@Configuration
//@EnableWebSecurity
public class Config {
    UserRepository userRepository;
    JWT_lanJie jwtLanJie;
    @Autowired
    Config(UserRepository userRepository,JWT_lanJie jwtLanJie){
        this.userRepository=userRepository;
        this.jwtLanJie=jwtLanJie;
    }
    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http
                .authorizeHttpRequests(auth -> auth
                        .anyRequest().permitAll() // ✅ 让拦截器处理认证逻辑
                )
                .csrf(csrf -> csrf.disable())
                .sessionManagement(session -> session.disable()); // 禁用session
        return http.build();
    }
}
